<template lang='pug'>
.znhj-one(v-show="isshow")
  Spbox(v-for="item in commodityArr",:key="item.id",:citem="item",:noper='true')
  a(v-if="hasShowMore",:href="moreurl").showmore
    span 查看更多
    i 
</template>
<script>
import { pro } from '@/config/env'
import { unique } from '@/config/utils'
import fetch from '@/config/fetch'
import { getCommodityData } from '@/service/getData'
import Spbox from './_spbox'

export default {
  data() {
    return {
      commodityArr: [],
      isshow: true,
      moreurl:'hahaha',
      hasShowMore: false,// 是否有showmore链接
    }
  },
  created() {
    if (!this.cdata[0].tag) {
      this.isshow = false
      return
    }
    if (this.cdata[0].tag.length !=0) {
      this.render()
    }
  },
  props: ['cdata'],
  methods: {
    render() {
      let c = this.cdata[0].tag[0].elementName // 智能货架标识
      let p = this.$store.state.position
      let callback = 'b'+Math.floor(Math.random()*100000)
      fetch({
        url:`${pro}/homePage/getSmartShelfCmmdtysJsonp/${p.cityCode}_${p.storeLocation}_${c}_wap_3.2.2_${callback}.htm`,
        params:{},
        jsonpCallback: callback
      }).then(res=>{
        if (res.resultMsg != '成功' || res.resultData.length == '0' ) {
          this.isshow = false
          return
        }
        this.commodityArr = res.resultData
        if (res.resultData[0].showMore == '') {
          this.hasShowMore = false
        }else {
          this.moreurl = res.resultData[0].showMore
          this.hasShowMore = true
        }
      })
    }
  },
  components: {
    Spbox
  },
}
</script>
<style lang='scss' scoped>
@import './tool.scss';
.znhj-one {
  width: _(750);
  .showmore {
    display: block;
    width: 100%;
    height: _(80);
    background-color: #fff;
    line-height: _(80);
    text-align: center;
    font-size: _(24);
    color: #666;
    border-top: 1px solid #f7f7f7;
    i {
      display: inline-block;
      margin-left: _(10);
      width: _(10);
      height: _(17);
      background: url('/static/images/rightb.png');
      background-size: 100% 100%;
    }
  }
}
</style>  